package formulasimulator;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class FormulaSimulator
{

    public static void main(String[] args)
    {
        try (ServerSocket serverSocket = new ServerSocket(2727))
        {
            Socket socket = null;
            SendingThread thread = null;
            int counter = 1;
            
            while (true)
            {
                System.out.println("Waiting for client");
                socket = serverSocket.accept();
                System.out.println("Client " + socket.getInetAddress().getHostAddress() + " connected");
                
                if (thread != null)
                {
                    thread.drop();
                }
                thread = new SendingThread(counter++, socket);
                thread.start();
            }
        }
        catch (IOException ex)
        {
            System.err.println(ex);
        }
    }
}
